﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sinacor.Infra.UI.Controls.SmartClient
{
    public enum ErrorType
    {
        ServerError,
        ClientValidationError,
        ClientGeneralError
    }

    [Serializable]
    public class ErrorDetail : Sinacor.Infra.UI.Common.ErrorDetail
    {
        public ErrorDetail(int id)
            : base(id)
        {
        }

        public ErrorDetail(int id, string message)
            : base(id, message)
        {
        }

        public ErrorDetail(int id, string message, ErrorType type)
            : this(id, message)
        {
            _type = type;
        }

        private ErrorType _type;
        public ErrorType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        public static List<ErrorDetail> CreateFromException(Exception exception, ErrorType type)
        {
            return CreateFromException(exception).ConvertAll<ErrorDetail>(e => new ErrorDetail(e.Id, e.Message, type));
        }

        public static ErrorDetail CreateFromResourceKey(string resourceKey, ErrorType type, params object[] parameters)
        {
            Sinacor.Infra.UI.Common.ErrorDetail errorDetail = CreateFromResourceKey(resourceKey, parameters);
            return new ErrorDetail(errorDetail.Id, errorDetail.Message, type);
        }
    }
}
